home *** CD-ROM | disk | FTP | other *** search
/ PD Collection CD 1 / PD Collection CD 1.iso / textual / pdftops / xpdf / h / Dict < prev    next >
Text File  |  1996-06-08  |  1KB  |  70 lines

  1. //========================================================================
  2. //
  3. // Dict.h
  4. //
  5. // Copyright 1996 Derek B. Noonburg
  6. //
  7. //========================================================================
  8.  
  9. #ifndef DICT_H
  10. #define DICT_H
  11.  
  12. #ifdef __GNUC__
  13. //#pragma interface
  14. #endif
  15.  
  16. #include "Object.h"
  17.  
  18. //------------------------------------------------------------------------
  19. // Dict
  20. //------------------------------------------------------------------------
  21.  
  22. struct DictEntry {
  23.   char *key;
  24.   Object val;
  25. };
  26.  
  27. class Dict {
  28. public:
  29.  
  30.   // Constructor.
  31.   Dict();
  32.  
  33.   // Destructor.
  34.   ~Dict();
  35.  
  36.   // Reference counting.
  37.   int incRef() { return ++ref; }
  38.   int decRef() { return --ref; }
  39.  
  40.   // Get number of entries.
  41.   int getLength() { return length; }
  42.  
  43.   // Add an entry.  NB: does not copy key.
  44.   void add(char *key, Object *val);
  45.  
  46.   // Check if dictionary is of specified type.
  47.   GBool is(char *type);
  48.  
  49.   // Look up an entry and return the value.  Returns a null object
  50.   // if <key> is not in the dictionary.
  51.   Object *lookup(char *key, Object *obj);
  52.   Object *lookupNF(char *key, Object *obj);
  53.  
  54.   // Iterative accessors.
  55.   char *getKey(int i);
  56.   Object *getVal(int i, Object *obj);
  57.   Object *getValNF(int i, Object *obj);
  58.  
  59. private:
  60.  
  61.   DictEntry *entries;        // array of entries
  62.   int size;            // size of <entries> array
  63.   int length;            // number of entries in dictionary
  64.   int ref;            // reference count
  65.  
  66.   DictEntry *find(char *key);
  67. };
  68.  
  69. #endif
  70.